package cn.yu.dream.operation.biz.authority.controller;

import cn.yu.dream.common.core.util.R;
import cn.yu.dream.operation.api.entity.OperationRole;
import cn.yu.dream.operation.biz.authority.service.OperationRoleService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import org.springframework.http.HttpHeaders;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Set;

@RestController
@AllArgsConstructor
@RequestMapping("/role")
@Tag(name = "角色管理")
@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
public class OperationRoleController {

	private final OperationRoleService operationRoleService;

	@Operation(summary = "根据id查询角色", description = "根据id查询角色")
	@GetMapping("/getById/{id:\\d+}")
	public R<OperationRole> getById(@PathVariable Long id) {
		OperationRole user = operationRoleService.getById(id);
		return R.ok(user);
	}

	@Operation(summary = "新增角色", description = "新增角色")
	@PutMapping("/save")
	public R<OperationRole> saveEntity(@RequestBody OperationRole entity) {
		operationRoleService.save(entity);
		return R.ok(entity);
	}

	@Operation(summary = "修改角色", description = "修改角色")
	@PostMapping("/updateById")
	public R<OperationRole> updateEntityById(@RequestBody OperationRole entity) {
		operationRoleService.updateById(entity);
		return R.ok(entity);
	}

	@Operation(summary = "删除角色", description = "删除角色")
	@PostMapping("/removeById/{id:\\d+}")
	public R<Boolean> updateEntityById(@PathVariable Long id) {
		Boolean b = operationRoleService.removeById(id);
		return R.ok(b);
	}

	@Operation(summary = "全部角色", description = "全部角色")
	@GetMapping("/listAll")
	public R<List<OperationRole>> listAll() {
		List<OperationRole> list = operationRoleService.listAll();
		return R.ok(list);
	}

	@Operation(summary = "根据ids查询角色列表", description = "根据ids查询角色列表")
	@PostMapping("/listByIds")
	public R<List<OperationRole>> listByIds(@RequestBody Set<Long> ids) {
		List<OperationRole> list = operationRoleService.listByIds(ids);
		return R.ok(list);
	}
}
